import {createSlice} from "@reduxjs/toolkit";
import {getFindByParentId} from "@/api/dict";
import {useSelector} from "react-redux";
const dictSlice = createSlice({
    name:"dict",
    initialState:{
        dictList:[],// 保存获取过来的数据字典数据
    },
    reducers:{
        upDictList(state,{payload}){
            state.dictList = payload;
        }
    }
})
const {upDictList} = dictSlice.actions;
export const getFindByParentIdAsync = (parentId:number)=>{
    return async (dispatch:any)=>{
        const result = await getFindByParentId(parentId);
        dispatch(upDictList(result.data));
    }
}
export const useSelectorDict = ()=> useSelector((state:any)=>state.dict);
export default dictSlice.reducer;